package com.maxd.modules.redPacket.controller;

import com.maxd.adapter.IgnoreSecurity;
import com.maxd.error.Result;
import com.maxd.error.ResultUtil;
import com.maxd.modules.redPacket.entity.RedPacket;
import com.maxd.modules.redPacket.service.IRedPacketDetailsService;
import com.maxd.modules.redPacket.service.IRedPacketService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @author fang
 * @date 2021/1/14
 */
@RestController
@Api(value = "红包", tags = {"红包"})
@RequestMapping(value = "/redPacket")
public class RedPacketController {

    @Autowired
    private IRedPacketDetailsService redPacketDetailsService;
    @Autowired
    private IRedPacketService redPacketService;

    @PostMapping("/insertRedPacket")
    @ApiOperation("创建或查询红包（用户端）")
    public Result insertRedPacket(Long userId){
        return ResultUtil.success(redPacketService.insertRedPacket(userId));
    }

    @PostMapping("/helpTakeRedPacket")
    @ApiOperation("助力红包（用户端）")
    public Result helpTakeRedPacket(Long userId,String code){
        return ResultUtil.success(redPacketService.helpTakeRedPacket(userId,code));
    }

    @GetMapping("/confirm")
    @ApiOperation("app登陆助力")
    public Result confirm(Long userId){
        redPacketService.confirm(userId);
        return ResultUtil.success();
    }

    @GetMapping("/getLink")
    @ApiOperation("生成推广链接App（用户端）")
    public Result getLink(Long redPacketId){
        return ResultUtil.success(redPacketService.getLink(redPacketId));
    }

    @GetMapping("/getLinkQrCode")
    @ApiOperation("生成推广二维码）")
    @IgnoreSecurity
    public void getLinkQrCode(Long redPacketId,HttpServletResponse response){
        redPacketService.getLinkQrCode(redPacketId,response);
    }

    @GetMapping("/getDayMoney")
    @ApiOperation("今日累计送出红包")
    public Result getDayMoney(){
        return ResultUtil.success(redPacketService.getDayMoney());
    }


    @GetMapping("/selectRedPacketDetailsList")
    @ApiOperation("查询红包砍价记录（用户端）")
    public Result selectRedPacketDetailsList(Integer page,Integer size,Long redPacketId){
        return ResultUtil.success(redPacketDetailsService.selectRedPacketDetailsList(page,size,redPacketId));
    }

    @GetMapping("/selectRedPacketListByUserId")
    @ApiOperation("查询自己提现成功记录（用户端）")
    public Result selectRedPacketListByUserId(Integer page,Integer size,Long userId){
        return ResultUtil.success(redPacketService.selectRedPacketListByUserId(page,size,userId));
    }

    @GetMapping("/selectRedPacketListByUserIds")
    @ApiOperation("查询自己提现红包记录（管理端）")
    public Result selectRedPacketListByUserIds(Integer page,Integer size,Long userId,Integer status){
        return ResultUtil.success(redPacketService.selectRedPacketListByUserIds(page,size,userId,status));
    }

    @GetMapping("/selectRedPacketListByStatus")
    @ApiOperation("查询最近提现成功的人（用户端）")
    public Result selectRedPacketListByStatus(Integer page,Integer size){
        return ResultUtil.success(redPacketService.selectRedPacketListByStatus(page,size));
    }

    @GetMapping("/selectRedPacketList")
    @ApiOperation("查询红包记录（管理端）")
    public Result selectRedPacketList(Integer page,Integer size,Integer status){
        return ResultUtil.success(redPacketService.selectRedPacketListByStatuss(page,size,status));
    }

    @GetMapping("/withdrawDeposit")
    @ApiOperation("提现")
    public Result withdrawDeposit(Long redPacketId){
        return ResultUtil.success(redPacketService.withdrawDeposit(redPacketId));
    }




}